﻿using ComicBook.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity.Migrations;

namespace ComicBook.Data
{
    public class Seeder
    {
        public static void Seed(ApplicationDbContext db, bool seedComics = true, bool seedAuthors = true, bool seedCharacters = true, bool seedAuthorComic = true)
        {
            if (seedComics)
            {
                db.Comics.AddOrUpdate(
                    p => p.Title,
                    new Comic { Title = "Daredevil", Image = "http://upload.wikimedia.org/wikipedia/en/1/14/Daredevil_65.jpg" },
                    new Comic { Title = "Hulk", Image = "http://upload.wikimedia.org/wikipedia/en/3/3e/Incredible-hulk-20060221015639117.jpg" },
                    new Comic { Title = "Iron Man", Image = "http://upload.wikimedia.org/wikipedia/en/c/c4/IronMan-3.jpg" },
                    new Comic { Title = "Superman", Image = "http://upload.wikimedia.org/wikipedia/en/a/a6/Superman_1.jpg" },
                    new Comic { Title = "Green Lantern", Image = "http://upload.wikimedia.org/wikipedia/en/d/d1/Green_Lantern_v1_1.jpg" },
                    new Comic { Title = "The Flash", Image = "http://upload.wikimedia.org/wikipedia/en/2/22/Flash_Pack.jpg" },
                    new Comic { Title = "Sin City", Image = "http://upload.wikimedia.org/wikipedia/en/d/da/Sin_City_Hard_Goodbye.jpg" },
                    new Comic { Title = "Batman: The Dark Knight Strikes Again", Image = "http://upload.wikimedia.org/wikipedia/en/a/a8/BatmanDK2.jpg" }
                    );
                db.SaveChanges();
            }
            if (seedAuthors)
            {
                db.Authors.AddOrUpdate(
                    new Author{Name="Stan Lee", Image="http://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Stantheman.jpg/640px-Stantheman.jpg"},
                    new Author { Name = "Geoff Johns", Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/0/0a/8.31.11GeoffJohnsNew52ByLuigiNovi1.jpg/230px-8.31.11GeoffJohnsNew52ByLuigiNovi1.jpg" },
                    new Author { Name = "Frank Miller", Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/9/99/FrankMillerSanDiego_crop.jpg/640px-FrankMillerSanDiego_crop.jpg" }
                    );
                db.SaveChanges();
            }
            if (seedCharacters)
            {
                db.Characters.AddOrUpdate(
                    p => p.Name,
                    new Character { Name = "Matt Murdock", ComicId = 1 },
                    new Character { Name = "Daredevil", ComicId = 1 },
                    new Character { Name = "Bruce Banner", ComicId = 2 },
                    new Character { Name = "Hulk", ComicId = 2 },
                    new Character { Name = "Tony Stark", ComicId = 3 },
                    new Character { Name = "Iron Man", ComicId = 3 },
                    new Character { Name = "Clark Kent", ComicId = 4 },
                    new Character { Name = "Superman", ComicId = 4 },
                    new Character { Name = "Green Lanturn", ComicId = 5 },
                    new Character { Name = "Alan Scott", ComicId = 5 },
                    new Character { Name = "The Flash", ComicId = 6 },
                    new Character { Name = "Marv", ComicId = 7 },
                    new Character { Name = "John Hartigan", ComicId = 7 },
                    new Character { Name = "Gail", ComicId = 7 },
                    new Character { Name = "Bruce Wayne", ComicId = 8 },
                    new Character { Name = "Batman", ComicId = 8 }
                    );
                db.SaveChanges();
            }
            if (seedAuthorComic)
            {
                db.AuthorComic.AddOrUpdate(
                    p => new { p.AuthorId, p.ComicId },
                        new AuthorComicBook { AuthorId = 1, ComicId = 1 },
                        new AuthorComicBook { AuthorId = 1, ComicId = 2 },
                        new AuthorComicBook { AuthorId = 1, ComicId = 3 },
                        new AuthorComicBook { AuthorId = 1, ComicId = 4 },
                        new AuthorComicBook { AuthorId = 2, ComicId = 5 },
                        new AuthorComicBook { AuthorId = 2, ComicId = 6 },
                        new AuthorComicBook { AuthorId = 3, ComicId = 7 },
                        new AuthorComicBook { AuthorId = 3, ComicId = 8 }
                    );
                db.SaveChanges();
            }
        }
    }
}
